from collections.abc import Generator
from http.client import responses
from typing import Any

import requests
from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage

class JinaExampleTool(Tool):
    def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:

        url = tool_parameters['url']

        try:
            response = requests.get("https://r.jina.ai/" + url)
            response.raise_for_status()

            yield self.create_json_message({
                "result": response.text
            })

            # yield self.create_text_message(response.text)

        except requests.exceptions.HTTPError as errh:
            yield self.create_json_message({
                "result": f"请求失败：{str(errh)}"
            })



